#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct space{
    int st,en;
    bool operator<(space s2)const{
        if(st!=s2.st) return st<s2.st;
        return en<s2.en;
    }
};
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        int n,m,L,d[100000],cnt=0,sfx[100001],ans=0,idx=0,sl=0;
        long long v[100000],a[100000],p[100000],mv;
        space s[100000];
        memset(sfx,0x3f,sizeof sfx);
        scanf("%d %d %d %d",&n,&m,&L,&mv);
        int debugcnt=0;
        for(int i=0;i<n;i++){
            scanf("%d %lld %lld",&d[i],&v[i],&a[i]);
            if(v[i]>mv) debugcnt++;
        }
        for(int i=0;i<m;i++) scanf("%lld",&p[i]);
        for(int i=0;i<n;i++){
            int l=0,r=m-1,mid;
            while(l<r){
                mid=(l+r)>>1;
                if(p[mid]<d[i]) l=mid+1;
                else r=mid;
            }
            int fr=l;
            if(a[i]>=0){
                l=fr,r=m,mid;
                while(l<r){
                    mid=(l+r)>>1;
                    if(v[i]*v[i]+2*a[i]*(p[mid]-d[i])>mv*mv) r=mid;
                    else l=mid+1;
                }
                if(m-1>=l&&d[i]<=p[m-1]){
                    cnt++;
                    s[sl++]={l,m-1};
                }
            }else{
                l=fr-1,r=m-1;mid;
                while(l<r){
                    mid=(l+r+1)>>1;
                    if(v[i]*v[i]+2*a[i]*(p[mid]-d[i])>mv*mv) l=mid;
                    else r=mid-1;
                }
                if(l>=fr){
                    cnt++;
                    s[sl++]={fr,l};
                }
            }
        }
        sort(s,s+sl);
        for(int i=sl-1;i>=0;i--) sfx[i]=min(sfx[i+1],s[i].en);
        while(idx<sl){
            int l=idx,r=sl,mid;
            while(l<r){
                mid=(l+r)>>1;
                if(s[mid].st>sfx[idx]) r=mid;
                else l=mid+1;
            }
            idx=l,ans++;
        }
        printf("%d %d\n",cnt,m-ans);
    }
    return 0;
}
